import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { useContainer } from 'class-validator';
import {
  FastifyAdapter,
  NestFastifyApplication,
} from '@nestjs/platform-fastify';
import { configure } from './modules/core/configure';

async function bootstrap() {
  const app = await NestFactory.create<NestFastifyApplication>(
    AppModule,
    new FastifyAdapter(),
  );
  applyKey();
  app.enableCors();
  useContainer(app.select(AppModule), {
    fallbackOnErrors: true,
  });
  // eslint-disable-next-line @typescript-eslint/no-var-requires
  app.register(require('@fastify/multipart'), {
    attachFieldsToBody: true,
  });
  await app.listen(3000, '0.0.0.0', (err, address) => {
    if (err) {
      console.error(err);
      return;
    }
    console.log(`Server listening on ${address}`);
  });
}
bootstrap();

function applyKey() {
  // eslint-disable-next-line @typescript-eslint/no-var-requires
  const COS = require('cos-nodejs-sdk-v5');
  const cos = new COS({
    SecretId: 'AKIDyoRq1wjJpAH8m24tUr1wcHn45pKacO3U',
    SecretKey: 'LUQL6buymKcjpjNXTPMGAykLobCZq01n',
  });
  configure.cos = cos;
}
